/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */

 //中序遍历

class Solution {
public:
    bool help(TreeNode* root,long long & pre_val)
    {
        if(!root) return true;
        if(!help(root->left,pre_val)) return false;
        if(root->val<=pre_val) return false;
        pre_val=root->val;
        if(!help(root->right,pre_val)) return false;
        return true;
    }
    bool isValidBST(TreeNode* root) {
        long long pre_val=LONG_MIN;
        return help(root,pre_val);
    }
};
